package com.chixing.ih.module.task.mapper;

import com.chixing.ih.common.IhRepository;
import com.chixing.ih.module.task.mapper.provider.OrderMapperProvider;
import com.chixing.ih.module.task.mapper.provider.TaskMapperProvider;
import com.chixing.ih.module.task.pojo.DTO.OrderDTO;
import com.chixing.ih.module.task.pojo.DTO.OrderListDTO;
import com.chixing.ih.module.task.pojo.DTO.ProCommentDTO;
import com.chixing.ih.module.task.pojo.DTO.TaskShowDTO;
import com.chixing.ih.module.task.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.time.Year;
import java.util.List;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/9/25 23:02
 */

@Mapper
public interface OrderMapper extends IhRepository<Order> {
    @Override
    @InsertProvider(type = OrderMapperProvider.class, method = "insertOne")
    int insertOne(Order order);

    @DeleteProvider(type = OrderMapperProvider.class, method = "delOne")
    int deleteOne(Long orderId);

    @DeleteProvider(type = OrderMapperProvider.class, method = "deleteAll")
    int deleteAll(Long userId);


    @SelectProvider(type = OrderMapperProvider.class, method = "getOne")
    @Results(id = "orderMap", value = {
            @Result(id = true, column = "order_id", property = "orderId"),
            @Result(column = "order_num", property = "orderNum"),
            @Result(column = "send_task_user_id", property = "sendTaskUserId"),
            @Result(column = "receive_task_user_id", property = "receiveTaskUserId"),
            @Result(column = "task_id", property = "taskId"),
            @Result(column = "salary", property = "salary"),
            @Result(column = "order_begin_time", property = "orderBeginTime"),
            @Result(column = "order_end_time", property = "orderEndTime"),
            @Result(column = "order_status", property = "orderStatus"),
            @Result(column = "is_deleted", property = "logicalDeletion"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
    })
    Order getOne(Long id);

    //根据任务id获取订单
    @ResultMap({"orderMap"})
    @SelectProvider(type = OrderMapperProvider.class, method = "findOne")
    Order findOne(Long taskId);

    @SelectProvider(type = OrderMapperProvider.class, method = "findOrders")
    @ResultMap({"orderMap"})
    List<Order> findOrders(Order order);


    @SelectProvider(type = OrderMapperProvider.class, method = "findAll")
    @Results(id = "orderMaps", value = {
            @Result(id = true, column = "order_id", property = "order.orderId"),
            @Result(column = "order_num", property = "order.orderNum"),
            @Result(column = "send_task_user_id", property = "order.sendTaskUserId"),
            @Result(column = "receive_task_user_id", property = "order.receiveTaskUserId"),
            @Result(column = "task_id", property = "order.taskId"),
            @Result(column = "salary", property = "order.salary"),
            @Result(column = "order_begin_time", property = "order.orderBeginTime"),
            @Result(column = "order_end_time", property = "order.orderEndTime"),
            @Result(column = "order_status", property = "order.orderStatus"),
            @Result(column = "is_deleted", property = "order.logicalDeletion"),
            @Result(column = "create_time", property = "order.createTime"),
            @Result(column = "update_time", property = "order.updateTime"),
            @Result(column = "task_title", property = "task.mandateTitle"),
            @Result(column = "talent_categories", property = "task.talentCategory"),
            @Result(column = "requirement_description", property = "task.requirementsDescription"),
            @Result(column = "technology", property = "task.skillsRequirements"),
            @Result(column = "work_way", property = "task.operationMode"),
            @Result(column = "salary", property = "task.salary"),
            @Result(column = "work_cycle", property = "task.workCycle"),
            @Result(column = "work_place", property = "task.workPlace"),
            @Result(column = "publishing_name", property = "task.isSuerName"),
            @Result(column = "publishing_phone", property = "task.isSuerTelephone"),
            @Result(column = "task_status", property = "task.taskStatus"),
            @Result(column = "type_status", property = "task.releaseStatus"),
            @Result(column = "is_deleted", property = "task.logicalDeletion"),
            @Result(column = "create_time", property = "task.createTime"),
            @Result(column = "update_time", property = "task.updateTime"),
            @Result(column = "is_sign", property = "task.marked"),
            @Result(column = "is_refresh", property = "task.refreshing"),
            @Result(column = "user_account", property = "sendUser.userAccount"),
            @Result(column = "nick_name", property = "sendUser.nickName"),
            @Result(column = "user_password", property = "sendUser.userPassword"),
            @Result(column = "user_telephone", property = "sendUser.userTelephone"),
            @Result(column = "user_status", property = "sendUser.userStatus"),
            @Result(column = "user_career", property = "sendUser.userCareer"),
            @Result(column = "user_career_direct", property = "sendUser.userCareerDirect"),
            @Result(column = "user_position", property = "sendUser.userPosition"),
            @Result(column = "user_company", property = "sendUser.userCompany"),
            @Result(column = "user_email", property = "sendUser.userEmail"),
            @Result(column = "support_num", property = "sendUser.supportNum"),
            @Result(column = "alipay_account", property = "sendUser.alipayAccount"),
            @Result(column = "wechat_account", property = "sendUser.wechatAccount"),
            @Result(column = "qq_account", property = "sendUser.qqAccount"),
            @Result(column = "role_id", property = "sendUser.roleId"),
            @Result(column = "user_account", property = "receiveUser.userAccount"),
            @Result(column = "nick_name", property = "receiveUser.nickName"),
            @Result(column = "user_password", property = "receiveUser.userPassword"),
            @Result(column = "user_telephone", property = "receiveUser.userTelephone"),
            @Result(column = "user_status", property = "receiveUser.userStatus"),
            @Result(column = "user_career", property = "receiveUser.userCareer"),
            @Result(column = "user_career_direct", property = "receiveUser.userCareerDirect"),
            @Result(column = "user_position", property = "receiveUser.userPosition"),
            @Result(column = "user_company", property = "receiveUser.userCompany"),
            @Result(column = "user_email", property = "receiveUser.userEmail"),
            @Result(column = "support_num", property = "receiveUser.supportNum"),
            @Result(column = "alipay_account", property = "receiveUser.alipayAccount"),
            @Result(column = "wechat_account", property = "receiveUser.wechatAccount"),
            @Result(column = "qq_account", property = "receiveUser.qqAccount"),
            @Result(column = "role_id", property = "receiveUser.roleId")
    })
    List<OrderListDTO> findAll();

    @Override
    @UpdateProvider(type = OrderMapperProvider.class, method = "updateOne")
    int updateOne(Order order);


    @SelectProvider(type = OrderMapperProvider.class, method = "findCompletedTaskSuccess")
    @Results(id = "taskIdMap", value = {
            @Result(id = true, column = "order_id", property = "orderId"),
            @Result(column = "task_id", property = "taskId"),
            @Result(column = "payment_status", property = "paymentStatus")
    })
    List<Order> findCompletedTaskSuccess(Long userId);

    @SelectProvider(type = OrderMapperProvider.class, method = "findCompletedTaskFailure")
    @ResultMap({"taskIdMap"})
    List<Order> findCompletedTaskFailure(Long userId);

    @SelectProvider(type = OrderMapperProvider.class, method = "findCompletedEmploymentSuccess")
    @ResultMap({"taskIdMap"})
    List<Order> findCompletedEmploymentSuccess(Long userId);


    @SelectProvider(type = OrderMapperProvider.class, method = "findCompletedEmploymentFailure")
    @ResultMap({"taskIdMap"})
    List<Order> findCompletedEmploymentFailure(Long userId);

    @SelectProvider(type = OrderMapperProvider.class, method = "findProgressTask")
    @ResultMap({"taskIdMap"})
    List<Order> findProgressTask(Long userId);

    @SelectProvider(type = OrderMapperProvider.class, method = "findProgressEmployment")
    List<TaskShowDTO> findProgressEmployment(Long userId);

    @UpdateProvider(type = OrderMapperProvider.class, method = "updateOne")
    int applicationSettlement(Order order);

    @UpdateProvider(type = OrderMapperProvider.class, method = "updateOne")
    int applyRefund(Order order);

    @SelectProvider(type = OrderMapperProvider.class, method = "orderTotalNumber")
    long orderTotalNumber();

    @UpdateProvider(type = OrderMapperProvider.class, method = "updateOrder")
    int updateOrder(Order order);

    @SelectProvider(type = OrderMapperProvider.class, method = "getPendingComOrder")
    ProCommentDTO getPendingComOrder(Long orderId);

    @SelectProvider(type = OrderMapperProvider.class, method = "getOneOrder")
    OrderDTO getOneOrder(Long orderId);

}
